﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using CoolCode;
using CoolCode.Linq;
using CoolCode.Linq.Expressions;
using CoolCode.Data;
using CoolCode.Services;
using XNoteBook.Entities;
using XNoteBook.Models;

namespace XNoteBook.Services.Implement
{
	public class CommonService : ServiceBase, ICommonService
	{
		#region Data Access Objects

		private IRepository<DictionaryItem> _DictionaryItemDao;
		public IRepository<DictionaryItem> DictionaryItemDao
		{
			get
			{
				if (_DictionaryItemDao == null)
				{
					_DictionaryItemDao = this.CreateRepository<DictionaryItem>();
				}
				return _DictionaryItemDao;
			}
			set
			{
				_DictionaryItemDao = value;
			}
		}

		#endregion

		#region ICommonService Members

		public IEnumerable<DictionaryItem> GetDictionaryItems(string name)
		{
			var query = from c in this.DictionaryItemDao
						where c.Name == name
						orderby c.SortIndex
						select c;
			return query;
		}

		public IEnumerable<ValueText> ListValueText(string name)
		{
			var query = from c in this.DictionaryItemDao
						where c.Name == name
						orderby c.SortIndex
						select new ValueText
						{
							Value = c.Value,
							Text = c.Text
						};
			return query;
		}
		#endregion
	}
}
